package com.ruoyi.pay.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AlipayConfig {


    @Value("${alipay.URL}")
    private String URL;

    @Value("${alipay.APP_ID}")
    private String APP_ID;

    @Value("${alipay.APP_PRIVATE_KEY}")
    private String APP_PRIVATE_KEY;

    @Value("${alipay.ALIPAY_PUBLIC_KEY}")
    private String ALIPAY_PUBLIC_KEY;

    // 签名方式
    public static String sign_type = "RSA2";

    // 字符编码格式
    public static String charset = "utf-8";

    // 支付宝网关
    public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

    // 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String notify_url = "http://工程公网访问地址/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    public static String return_url = "http://工程公网访问地址/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";


    @Bean
    public AlipayClient alipayClient(){
        return new DefaultAlipayClient(
                URL, APP_ID, APP_PRIVATE_KEY,
                "json",
                AlipayConfig.charset,
                ALIPAY_PUBLIC_KEY,
                AlipayConfig.sign_type);
    }

}
